#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int p;
char data[5000],code[50000];

void
interpret(char *icode)
{
	int b;
	char *w;

	while (*icode) {
		switch (*icode++) {
			case '<': p--;break;
			case '>': p++;break;
			case '+': data[p]++;break;
			case '-': data[p]--;break;
			case '.': putchar(data[p]);fflush(stdout);break;
			case ',': data[p]=getchar();fflush(stdout);break;
			case '[':
				for (b=1,w=icode;b&&*icode;icode++)
					b+=*icode=='[',b-=*icode==']';
				if (!b) {
					icode[-1]=0;
					while (data[p])
						interpret(w);
					icode[-1]=']';
					break;
				}
			case ']':
				puts("unbalanced brackets"),exit(0);
			default:
				break;
		}
		if (p<0||p>=5000)
			puts("range error"),exit(0);
	}
}

int
main(int argc, char *argv[])
{
	FILE *fin;
	char *s=code,ch;

	if (fin=fopen(argv[1],"r")) {
		while ((ch=getc(fin))>=0)
			*s++=ch;
		*s=0;
		interpret(code);
	}
	return 0;
}
